//
//  YBBaseViewController.m
//  YBTool
//
//  Created by 陈亚勃 on 15/12/28.
//  Copyright © 2015年 cyb. All rights reserved.
//

#import "YBBaseViewController.h"

@interface YBBaseViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>

@end

@implementation YBBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark --- 相册功能
// 打开相机
- (void)openCamera
{
    //判断是否支持图像源
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        
        //创建图片拾取器
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        //设置图片源的类型
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        //设置代理
        imagePicker.delegate = self;
        
        imagePicker.allowsEditing = NO;  //允许编辑：放大，缩小
        [self presentViewController:imagePicker animated:YES completion:nil];
        
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"该设备没有照相机" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}

// 打开相册
- (void)openPhotoBook
{
    //创建图片拾取器
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    //设置图片源的类型
    imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    //设置代理
    imagePicker.delegate = self;
    
    imagePicker.allowsEditing = NO;  //允许编辑：放大，缩小
    [self presentViewController:imagePicker animated:YES completion:nil];
    
}

/**
 *  根据label的内容自动算高度
 *
 *  @param text label的内容
 *
 *  @return label的高度
 */
- (CGFloat)getLabelHeight:(NSString *)text stringFont:(NSInteger)font allowWidth:(CGFloat)width{
    CGFloat height;
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, 2000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil];
    height = rect.size.height;
    return height;
}

/**
 *  修改json数据中为null的数据
 *
 *  @param jsonDate json数据
 */
- (NSDictionary *)changeDicionaryWithJsonDictionary:(NSDictionary *)jsonDate{
    NSMutableDictionary *changeDic = [NSMutableDictionary dictionary];
    for (NSString *jsonKey in jsonDate) {
        id value = [jsonDate objectForKey:jsonKey];
        if ([value isKindOfClass:[NSNull class]]) {
            value = nil;
        }
        [changeDic setValue:value forKey:jsonKey];
    }
    return changeDic;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
